/*  1:   */ package org.jetbrains.generate.tostring.view;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.EditorFactory;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.openapi.util.Comparing;
import com.intellij.psi.PsiFile;
import org.jetbrains.generate.tostring.template.TemplateResource;

import javax.swing.*;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */ 
/* 16:   */ public class ToStringTemplateConfigurable
/* 17:   */   implements UnnamedConfigurable
/* 18:   */ {
/* 19:   */   private final TemplateResource a;
/* 20:   */   private final Editor b;
/* 21:   */   
/* 22:   */   public ToStringTemplateConfigurable(TemplateResource paramTemplateResource)
/* 23:   */   {
/* 24:39 */     this.a = paramTemplateResource;
/* 25:40 */     EditorFactory localEditorFactory = EditorFactory.getInstance();
/* 26:41 */     Document localDocument = localEditorFactory.createDocument(paramTemplateResource.getTemplate());
/* 27:42 */     this.b = (paramTemplateResource.isDefault() ? localEditorFactory.createViewer(localDocument) : localEditorFactory.createEditor(localDocument));
/* 28:   */   }
/* 29:   */   
/* 30:   */   public JComponent createComponent()
/* 31:   */   {
/* 32:46 */     return this.b.getComponent();
/* 33:   */   }
/* 34:   */   
/* 35:   */   public boolean isModified()
/* 36:   */   {
/* 37:50 */     return !Comparing.equal(this.b.getDocument().getText(), this.a.getTemplate());
/* 38:   */   }
/* 39:   */   
/* 40:   */   public void apply()
/* 41:   */     throws ConfigurationException
/* 42:   */   {
/* 43:54 */     this.a.setTemplate(this.b.getDocument().getText());
/* 44:   */   }
/* 45:   */   
/* 46:   */   public void reset()
/* 47:   */   {
/* 48:58 */     new WriteCommandAction(null, new PsiFile[0])
/* 49:   */     {
/* 50:   */       protected void run(Result paramAnonymousResult)
/* 51:   */         throws Throwable
/* 52:   */       {
/* 53:60 */         ToStringTemplateConfigurable.this.b.getDocument().setText(ToStringTemplateConfigurable.this.a.getTemplate());
/* 54:   */       }
/* 55:   */     }.execute();
/* 56:   */   }
/* 57:   */   
/* 58:   */   public void disposeUIResources()
/* 59:   */   {
/* 60:66 */     EditorFactory.getInstance().releaseEditor(this.b);
/* 61:   */   }
/* 62:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.generate.tostring.view.ToStringTemplateConfigurable

 * JD-Core Version:    0.7.0.1

 */